package com.lankystar.sos.dao.impl;

import java.util.List;
import java.util.Map;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.lankystar.sos.dao.IPharmacyDao;
import com.lankystar.sos.model.Pharmacy;
import com.lankystar.util.MathMethod;

@Repository
public class PharmacyDaoImpl implements IPharmacyDao{

	@Autowired
	private SessionFactory sf;
	public Session getSession(){
		System.out.println("session开启！！");
		return sf.getCurrentSession();
	}
	@SuppressWarnings("unchecked")
	@Override
	public List<Pharmacy> selectPharmacylist(Double longitude,Double latitude) {
		Map<String, Object> map = MathMethod.distance(longitude, latitude);
		String sql = "from Pharmacy p where p.longitude between "+map.get("minlng")+" and "
					+map.get("maxlng")+" and p.latitude between "+map.get("minlat")+" and "+map.get("maxlat")+"";
		List<Pharmacy> pharmacys = getSession().createQuery(sql).list();
		return pharmacys;
	}

}
